//
//  PlayTableViewCell.m
//  MMLOOK
//
//  Created by dllo on 15/10/9.
//  Copyright © 2015年 武俊娥. All rights reserved.
//

#import "PlayTableViewCell.h"
#import "Play.h"
#import "UIImageView+WebCache.h"


#define playHeight [UIScreen mainScreen].bounds.size.width * 777 / 1242

@interface PlayTableViewCell ()

@property(nonatomic, retain)UIImageView *image;
@property(nonatomic, retain)UILabel *nameLabel;
@property(nonatomic, retain)UILabel *timeLabel;
@property(nonatomic, retain)UIView *blackView;

@end


@implementation PlayTableViewCell


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.image = [[UIImageView alloc]init];
        [self.contentView addSubview:self.image];
        [_image release];
        
        self.blackView = [[UIView alloc]init];
        self.blackView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.1];
        [self.contentView addSubview:self.blackView];
        [_blackView release];
        
        self.nameLabel = [[UILabel alloc]init];
        self.nameLabel.textAlignment = NSTextAlignmentCenter;
        self.nameLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:20];
        self.nameLabel.textColor = [UIColor whiteColor];
        [self.contentView addSubview:self.nameLabel];
        [_nameLabel release];
        
        
        self.timeLabel = [[UILabel alloc]init];
        self.timeLabel.textAlignment = NSTextAlignmentCenter;
        self.timeLabel.font = [UIFont fontWithName:@"Helvetica" size:15];
        self.timeLabel.textColor = [UIColor whiteColor];
        [self.contentView addSubview:self.timeLabel];
        [_timeLabel release];
        
        
        
        
    }
    
    return self;
}


-(void)layoutSubviews
{
    [super layoutSubviews];
    
    self.image.frame = CGRectMake(0, 0,[UIScreen mainScreen].bounds.size.width, playHeight);
    
    self.blackView.frame = CGRectMake(0, 0,[UIScreen mainScreen].bounds.size.width, playHeight);
    
    self.nameLabel.frame = CGRectMake(0, playHeight / 5 * 2, [UIScreen mainScreen].bounds.size.width, playHeight / 5);
    
    self.timeLabel.frame = CGRectMake(0, playHeight / 5 * 3, [UIScreen mainScreen].bounds.size.width, playHeight / 5);
    
    
}


-(void)setPlay:(Play *)play
{
    if (_play != play) {
    
        [_play release];
        
        _play = [play retain];
    }
    
    
    [self.image sd_setImageWithURL:[NSURL URLWithString:play.coverForFeed] placeholderImage:[UIImage imageNamed:@""]];
   
    self.nameLabel.text = play.title;
    
    
    float time = [play.duration floatValue];
    NSInteger fen = time / 60;
    NSInteger miao = time - fen * 60;
    
    
    self.timeLabel.text = [NSString stringWithFormat:@"#%@  /  %ld' %ld\" ", play.category,fen,miao];
    
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
